package cn.hesion.leetcode;
/**
 * ClassName: DeckRevealedIncreasing <br/>
 * Description: <br/>
 * date: 2022/5/11 22:20<br/>
 *
 * @author Hesion<br />
 * @version
 * @since JDK 1.8
 */

import java.util.Arrays;
import java.util.Deque;
import java.util.LinkedList;

/**
 * @author: hesion
 * @create: 2022-05-11 22:20
 **/
public class DeckRevealedIncreasing {

    public int[] deckRevealedIncreasing(int[] deck) {
        int N = deck.length;
        Deque<Integer> index = new LinkedList();
        for (int i = 0; i < N; i++) {
            index.add(i);
        }
        int[] ans = new int[N];
        Arrays.sort(deck);
        for (Integer card : deck) {
            ans[index.pollFirst()] = card;
            if (!index.isEmpty()) {
                index.add(index.pollFirst());
            }
        }
        return ans;
    }
}
